package com.pig4cloud.mall.product.controller;

import com.pig4cloud.mall.product.entity.AttrGroup;
import com.pig4cloud.mall.product.service.AttrGroupService;
import com.pig4cloud.pig.common.core.util.PageResult;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 属性分组
 *
 * @author fangyu
 * @date 2020-11-25 15:05:25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/attrgroup" )
@Api(value = "attrgroup", tags = "属性分组管理")
public class AttrGroupController {

    private final  AttrGroupService attrGroupService;

    @RequestMapping("/list/{catId}")
	public R list(@RequestParam Map<String, Object> params, @PathVariable("catId") Long catId) {
		PageResult pageResult = attrGroupService.queryPage(params, catId);
		return R.ok(pageResult);
	}

    /**
     * 通过id查询属性分组
     * @param attrGroupId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{attrGroupId}" )
//    @PreAuthorize("@pms.hasPermission('product_attrgroup_get')" )
    public R getById(@PathVariable("attrGroupId" ) Long attrGroupId) {
        return R.ok(attrGroupService.getById(attrGroupId));
    }

    /**
     * 新增属性分组
     * @param attrGroup 属性分组
     * @return R
     */
    @ApiOperation(value = "新增属性分组", notes = "新增属性分组")
    @SysLog("新增属性分组" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('product_attrgroup_add')" )
    public R save(@RequestBody AttrGroup attrGroup) {
        return R.ok(attrGroupService.save(attrGroup));
    }

    /**
     * 修改属性分组
     * @param attrGroup 属性分组
     * @return R
     */
    @ApiOperation(value = "修改属性分组", notes = "修改属性分组")
    @SysLog("修改属性分组" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('product_attrgroup_edit')" )
    public R updateById(@RequestBody AttrGroup attrGroup) {
        return R.ok(attrGroupService.updateById(attrGroup));
    }

    /**
     * 通过id删除属性分组
     * @param attrGroupId id
     * @return R
     */
    @ApiOperation(value = "通过id删除属性分组", notes = "通过id删除属性分组")
    @SysLog("通过id删除属性分组" )
    @DeleteMapping("/{attrGroupId}" )
//    @PreAuthorize("@pms.hasPermission('product_attrgroup_del')" )
    public R removeById(@PathVariable Long attrGroupId) {
        return R.ok(attrGroupService.removeById(attrGroupId));
    }

}
